home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOpus Plus
/
DOpus Plus.iso
/
Enhancements
/
FTPBatch
/
ARexx
/
FTPBatchLister.dopus5
< prev
Wrap
Text File
|
1998-10-25
|
14KB
|
426 lines
/* $VER: FTPBatchLister.dopus 4.1 (25.10.98) (C) by Martin Steigerwald
*/
OPTIONS RESULTS
IF ~SHOW('L','rexxsupport.library') THEN CALL ADDLIB('rexxsupport.library',0,-30,0)
IF ~SHOW('L','rexxsupport.library') THEN EXIT
PARSE ARG opus ' ' handle ' ' config.fileprefix ' ' config.download
batchlistfile = config.fileprefix'.batch'
config.file = config.fileprefix'.config'
ADDRESS VALUE opus
appname='FTPBatchLister'
FORBID()
portname=appname'.0'
DO i = 0 WHILE SHOW('P', portname)
portname='FTPBatchLister.' || i
END
IF ~OPENPORT(portname) THEN DO
PERMIT()
DOPUS REQUEST '"'appname': Couldnt open port" OK'
END
PERMIT()
entrymenu.0 = "Edit Name"
entrymenu.1 = "Edit Site"
entrymenu.2 = "---"
entrymenu.3 = "Delete"
entrymenu.count = 4
LoadConfig()
/* --- DEBUG ---
debugging=1 --> FTPBatchDownload will be started with C:Run
to provide debugging output
*/
config.debugging=0
OpenLister()
LoadBatchlist()
/* autobatch mode */
IF config.download=='DOWNLOAD' THEN DO
config.logging=1
config.requesters=0
StartDownload(handle 'ALL AUTODOWNLOAD')
END
/* interactive mode */
DO FOREVER
IF WAITPKT(portname) THEN DO
packet = GETPKT(portname)
IF packet ~== '00000000'x THEN DO
event = UPPER(GETARG(packet,0))
SELECT
WHEN event = 'INACTIVE' THEN LEAVE
WHEN event = 'FTPBATCHCONFIG' THEN DO
cmdargs=STRIP(GETARG(packet,5))
IF cmdargs=='EDIT' THEN EditConfig()
IF cmdargs=='LOAD' THEN LoadConfig()
IF cmdargs=='SAVE' THEN SaveConfig()
IF cmdargs=='EDITSAVE' THEN DO
IF EditConfig()=1 THEN SaveConfig()
END
END
WHEN event = 'FTPBATCHLIST' THEN DO
cmdargs=STRIP(GETARG(packet,5))
IF cmdargs='SAVE' THEN SaveBatchlist()
IF cmdargs='LOAD' THEN LoadBatchlist()
END
WHEN event = 'FTPBATCHEDITENTRY' THEN DO
cmdargs=STRIP(GETARG(packet,5))
EditEntries(handle cmdargs)
END
WHEN event = 'DOUBLECLICK' THEN DO
cmdargs=STRIP(GETARG(packet,2))
EditEntry(handle 'name' '"'cmdargs'"')
END
WHEN event = 'DROP' THEN DO
sourcehandle = GETARG(packet,3)
filenames = GETARG(packet,2)
LISTER QUERY sourcehandle TITLE
sourcetitle=RESULT
IF LEFT(sourcetitle,4)~=='FTP:' THEN DO
LISTER REQUEST handle '"No FTP lister" OK'
END
ELSE DO
LISTER QUERY sourcehandle PATH
pathname=RESULT
AddEntries()
END /* IF */
END /* WHEN */
WHEN event = 'DELETE' THEN DO
filenames = GETARG(packet,2)
DeleteEntries()
END /* WHEN */
WHEN event = 'PATH' THEN DO
config.fileprefix=GETARG(packet,2)
batchlistfile = config.fileprefix'.batch'
config.file = config.fileprefix'.config'
LoadBatchlist()
LoadConfig()
END /* WHEN */
WHEN event = 'FTPBATCHDOWNLOAD' THEN DO
cmdargs=STRIP(GETARG(packet,5))
StartDownload(handle cmdargs)
END /* WHEN */
WHEN event = 'MENU' THEN DO
IF GETARG(packet,4)=='file' THEN DO
menuitem=GETARG(packet,3)
menuarg=GETARG(packet,2)
SELECT
WHEN menuitem=0 THEN DO
EditEntry(handle 'name "'menuarg'"')
END
WHEN menuitem=1 THEN DO
EditEntry(handle 'comment "'menuarg'"')
END
WHEN menuitem=3 THEN DO
filenames = '"'menuarg'"'
DeleteEntries()
END /* WHEN */
OTHERWISE DOPUS REQUEST '"Unknown menu entry »' || menuitem || '«!" OK'
END /* SELECT */
END /* IF */
END /* WHEN */
WHEN event = 'EDIT' THEN DO
entryname=GETARG(packet,2)
new=GETARG(packet,4)
field=GETARG(packet,3)
SetEntry(handle field '"'entryname'" "'new'"')
END /* WHEN */
OTHERWISE DOPUS REQUEST '"Unknown event type »' || event || '«!" OK'
END /* SELECT */
CALL REPLY(packet,0)
END /* IF */
END /* IF */
END /* DO */
Cleanup()
EXIT
Cleanup:
DOPUS REMTRAP '*' portname
DOPUS COMMAND "FTPBatchDownload" REMOVE
DOPUS COMMAND "FTPBatchConfig" REMOVE
DOPUS COMMAND "FTPBatchList" REMOVE
DOPUS COMMAND "FTPBatchEditEntry" REMOVE
CLOSEPORT(portname)
RETURN 1
EditConfig: PROCEDURE EXPOSE config.
res=0
DOPUS REQUEST '"How many simultaneous connections do you want?" 1|2|3|4|5|6|7|8|Cancel'
IF RC>0 THEN DO
editconfig.maxconnections=RC
DOPUS REQUEST '"How should FTPBatch behave?" Requesters|Both|Logging|Cancel'
IF RC>0 THEN DO
IF RC<3 THEN DO
editconfig.requesters=1
END
ELSE DO
editconfig.requesters=0
END
IF RC>1 THEN DO
editconfig.logging=1
END
ELSE DO
editconfig.logging=0
END
DOPUS GETSTRING '"Please enter the default download path." 200 "'config.downloadpath'" OK|Cancel'
IF RESULT~=='RESULT' THEN DO
config.downloadpath=RESULT
config.maxconnections=editconfig.maxconnections
config.requesters=editconfig.requesters
config.logging=editconfig.logging
res=1
END
END
END
RETURN res
SaveConfig: PROCEDURE EXPOSE config.
IF OPEN('fh', config.file, 'W') THEN DO
WRITELN('fh','FTPBatchConfig')
WRITELN('fh','MaxConnections =' config.maxconnections)
WRITELN('fh','DownloadPath =' config.downloadpath)
WRITELN('fh','Requesters =' config.requesters)
WRITELN('fh','Logging =' config.logging)
CLOSE('fh')
END
ELSE DO
DOPUS REQUEST '"Couldnt save config file!" Cancel'
END
RETURN 0
LoadConfig: PROCEDURE EXPOSE config.
config.maxconnections=1
config.downloadpath='RAM:'
config.requesters=1
config.logging=0
IF OPEN('fh', config.file, 'R') THEN DO
line=READLN('fh')
IF UPPER(line)=='FTPBATCHCONFIG' THEN DO
DO UNTIL EOF('fh')
line=STRIP(READLN('fh'))
PARSE VAR line option '=' setting
option=UPPER(STRIP(option))
setting=STRIP(setting)
config.option=setting
END
END
ELSE DO
DOPUS REQUEST '"File »'config.file'« is no FTPBatch config file!" Cancel'
END
CLOSE('fh')
END
RETURN 0
EditEntries: PROCEDURE
PARSE ARG handle ' ' field
LISTER SET handle BUSY OFF
LISTER QUERY handle SELFILES STEM selectedfiles.
IF selectedfiles.count>0 THEN DO
DO i=1 TO selectedfiles.count
j=i-1
IF EditEntry(handle field '"'selectedfiles.j'"')=0 THEN LEAVE
END
END
LISTER SET HANDLE BUSY OFF
RETURN 0
EditEntry: PROCEDURE EXPOSE entrymenu.
PARSE ARG handle ' ' field ' "'entryname'"'
LISTER SET handle BUSY ON
LISTER QUERY handle ENTRY '"'entryname'"' STEM editentry.
editentry.menu=entrymenu.
changed=0
IF UPPER(field)=='NAME' THEN DO
LISTER GETSTRING handle '"New name:" 108 "'editentry.name'" OK|Cancel|Cancel all'
IF (DOPUSRC=1 | DOPUSRC=-1) & editentry.name~=RESULT THEN DO
editentry.name=RESULT
changed=1
END
END
ELSE DO
LISTER GETSTRING handle '"New URL:" 255 "'editentry.comment'" OK|Cancel|Cancel all'
IF (DOPUSRC=1 | DOPUSRC=-1) & editentry.comment~=RESULT THEN DO
editentry.comment=RESULT
changed=1
END
END
IF changed=1 THEN DO
LISTER REMOVE handle '"'entryname'"'
LISTER ADDSTEM handle editentry.
LISTER REFRESH handle
END
LISTER SET handle BUSY OFF
RETURN DOPUSRC
SetEntry: PROCEDURE
PARSE ARG handle ' ' field ' "'entryname'"' '"'new'"'
LISTER QUERY handle ENTRY '"'entryname'"' STEM editentry.
LISTER REMOVE handle '"'entryname'"'
IF field=='name' THEN editentry.name=new
IF field=='comment' THEN editentry.comment=new
LISTER ADDSTEM handle editentry.
LISTER REFRESH handle
RETURN 0
OpenLister:
IF handle=0 THEN DO
LISTER NEW TOOLBAR 'FTPBatchToolbar' MODE name
handle = RESULT
IF handle=0 THEN DO
DOPUS REQUEST '"'appname': Couldnt open lister" OK'
EXIT
END
LISTER WAIT handle QUICK
END
ELSE DO
DOPUS REQUEST '"'appname': Not working right now!" OK'
EXIT
END /* IF */
LISTER SET handle FIELD 4 'FTPSite'
LISTER SET handle DISPLAY name comment
LISTER SET handle TITLE portname
LISTER SET handle PATH config.fileprefix
LISTER SET handle HANDLER portname QUOTES EDITING
DOPUS COMMAND "FTPBatchDownload" TEMP PRIVATE HANDLER
DOPUS COMMAND "FTPBatchConfig" TEMP PRIVATE HANDLER
DOPUS COMMAND "FTPBatchList" TEMP PRIVATE HANDLER
DOPUS COMMAND "FTPBatchEditEntry" TEMP PRIVATE HANDLER
DOPUS ADDTRAP FTPBatchDownload portname
DOPUS ADDTRAP FTPBatchConfig portname
DOPUS ADDTRAP FTPBatchList portname
DOPUS ADDTRAP FTPBatchEditEntry portname
DOPUS ADDTRAP Rename portname
DOPUS ADDTRAP Delete portname
DOPUS ADDTRAP Copy portname
DOPUS ADDTRAP Move portname
DOPUS ADDTRAP FTPCopy portname
LISTER REFRESH handle FULL
LISTER SET handle BUSY OFF
RETURN 0
StartDownload: PROCEDURE EXPOSE appname portname opus config.
PARSE ARG handle cmdargs
batchportnr=SUBSTR(portname, POS('.',portname))
batchport='FTPBatchDownload' || batchportnr
IF config.logging=1 THEN DO
logging=config.fileprefix
END
ELSE DO
logging=''
END
IF config.requesters=1 THEN DO
requesters='REQUESTERS'
END
ELSE DO
requesters='QUIET'
END
IF ~SHOW('P',batchport) THEN DO
IF config.debugging=1 THEN DO
ADDRESS COMMAND 'RUN DOpus5:ARexx/FTPBatchDownload.dopus5' opus portname handle config.maxconnections requesters '"'logging'"' '"'config.downloadpath'"' cmdargs
END
ELSE DO
ADDRESS AREXX 'DOpus5:ARexx/FTPBatchDownload.dopus5' opus portname handle config.maxconnections requesters '"'logging'"' '"'config.downloadpath'"' cmdargs
END
END
ELSE DO
LISTER REQUEST handle appname'": Batchdownload already running!" OK'
END /* IF */
RETURN 0
LoadBatchlist: PROCEDURE EXPOSE entrymenu. handle batchlistfile appname
LISTER SET handle BUSY ON
LISTER CLEAR handle
IF OPEN('fh', batchlistfile, 'R') THEN DO
IF READLN('fh')==appname'1.0' THEN DO
DO UNTIL EOF('fh')
entry.name=READLN('fh')
entry.type=-1
entry.menu=entrymenu
IF entry.name~=='' THEN DO
entry.comment=READLN('fh')
LISTER ADDSTEM handle entry.
END /* IF */
END /* DO */
END /* filecheck */
CLOSE('fh')
END /* IF OPEN */
LISTER REFRESH handle
LISTER SET handle BUSY OFF
RETURN 0
SaveBatchlist: PROCEDURE EXPOSE handle batchlistfile appname
LISTER SET handle BUSY ON
IF OPEN('fh', batchlistfile, 'W') THEN DO
WRITELN('fh', appname'1.0')
LISTER QUERY handle NUMENTRIES
entries=RESULT
DO i=1 TO entries
LISTER QUERY handle ENTRY '#' || i-1 STEM entry.
WRITELN('fh', entry.name)
WRITELN('fh', entry.comment)
END /* DO */
CLOSE('fh')
END /* IF OPEN */
LISTER SET handle BUSY OFF
RETURN 0
AddEntries: PROCEDURE EXPOSE entrymenu. handle sourcetitle filenames pathname
IF RIGHT(pathname,1)~=='/' & RIGHT(pathname,1)~==':' THEN pathname=pathname'/'
DO UNTIL filenames==''
PARSE VAR filenames '"' filename '"' filenames
filename=STRIP(filename)
newentry.comment=SUBSTR(sourcetitle,5) || '//' || pathname || filename
/* handle existing entries */
number=0
DO FOREVER
IF number=0 THEN DO
LISTER QUERY handle ENTRY filename
END
ELSE DO
LISTER QUERY handle ENTRY filename || '.' || number
END /* IF number */
IF RC~=0 THEN LEAVE
number=number+1
END
IF number>0 THEN filename=filename || '.' || number
newentry.name=filename
newentry.type=-1
newentry.menu=entrymenu
LISTER ADDSTEM handle newentry.
END /* DO */
LISTER REFRESH handle
RETURN 0
DeleteEntries: PROCEDURE EXPOSE handle filenames
DO UNTIL filenames==''
PARSE VAR filenames '"' filename '"' filenames
filename=STRIP(filename)
LISTER REMOVE handle '"'filename'"'
END /* DO */
LISTER REFRESH handle
RETURN 0